import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { formatToYuan } from '#/utils/common';
import { renderDictTag } from '#/utils/render';

/**
 * 退款状态选项
 */
export const refundStatusOptions = [
  {
    dictLabel: '退款申请',
    dictValue: 1,
    label: '退款申请',
    listClass: 'blue',
    value: 1,
  },
  {
    dictLabel: '退款成功',
    dictValue: 2,
    label: '退款成功',
    listClass: 'green',
    value: 2,
  },
  {
    dictLabel: '退款失败',
    dictValue: 3,
    label: '退款失败',
    listClass: 'red',
    value: 3,
  },
];

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入订单号',
    },
    fieldName: 'orderNo',
    label: '订单号',
  },
  {
    component: 'Select',
    componentProps: {
      allowClear: true,
      options: refundStatusOptions,
      placeholder: '请选择退款状态',
    },
    fieldName: 'status',
    label: '退款状态',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入微信流水号',
    },
    fieldName: 'transactionId',
    label: '微信流水号',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入退款申请流水ID',
    },
    fieldName: 'refundId',
    label: '退款申请流水',
  },
  {
    component: 'Input',
    componentProps: {
      placeholder: '请输入退款申请单号',
    },
    fieldName: 'outRefundNo',
    label: '退款申请单号',
  },
  {
    component: 'RangePicker',
    componentProps: {
      placeholder: ['开始时间', '结束时间'],
    },
    fieldName: 'createTime',
    label: '退款时间',
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    field: 'orderId',
    title: '订单ID',
    width: 100,
  },
  {
    field: 'orderNo',
    title: '订单号',
    width: 250,
  },
  {
    align: 'right',
    field: 'refundPrice',
    formatter: ({ cellValue }) => {
      return formatToYuan(cellValue);
    },
    title: '退款金额',
    width: 120,
  },
  {
    field: 'transactionId',
    title: '微信流水号',
    width: 250,
  },
  {
    field: 'refundId',
    title: '退款申请流水ID',
    width: 250,
  },
  {
    field: 'outRefundNo',
    title: '退款申请单号',
    width: 250,
  },
  {
    field: 'status',
    slots: {
      default: ({ row }) => {
        return row.status !== null && row.status !== undefined
          ? renderDictTag(row.status, refundStatusOptions)
          : '';
      },
    },
    title: '退款状态',
    width: 120,
  },
  {
    field: 'notifyContent',
    minWidth: 300,
    title: '通知内容',
  },
];
